//
//  MineList_SecViewController.m
//  CookGuest
//
//  Created by LiuYanJun on 15/9/18.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "MineList_SecViewController.h"

#import "AFN.h"
#define SCREEN_WIDTH self.view.bounds.size.width
#define SCREEN_HEIGHT self.view.bounds.size.height
#import "UIImageView+WebCache.h"
#import "MenuList_SecTableViewCell.h"
#import "HeightWithString.h"
#import "MenuList_SecView.h"
#import "HeightWithString.h"
#import "CookModel.h"



@interface MineList_SecViewController ()<UITableViewDataSource,UITableViewDelegate>


@property (nonatomic, retain) UIImageView *img;  // 图片
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) MenuList_SecView *menuList_SecView;


@property (nonatomic, retain) UILabel *tagBgLabel;

@property (nonatomic, assign) CGFloat height;


//用料
@property (nonatomic, retain) UILabel *materials;
@property (nonatomic, retain) UILabel *mat_main;
@property (nonatomic, retain) UILabel *mat_other;

@property (nonatomic, retain) UILabel *mat_main_Label;
@property (nonatomic, retain) UILabel *mat_other_Label;

@property (nonatomic, assign) CGFloat mat_height;
@property (nonatomic, assign) CGFloat bur_height;
@property (nonatomic, retain) UILabel *stepLabel;

@property (nonatomic, retain) NSMutableArray *lastArr;

@end

@implementation MineList_SecViewController


-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}


-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.lastArr = [[NSMutableArray alloc]init];
    
    self.menuList_SecView = [[MenuList_SecView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:self.menuList_SecView];
    
    
    for (NSMutableDictionary *dic in self.stepArr) {
        
        CookModel *cook = [[CookModel alloc]init];
        [cook setValuesForKeysWithDictionary:dic];
        
        
        cook.height = [HeightWithString heightForTextLabel:cook.step width:SCREEN_WIDTH - 40 fontSize:16];
        
        
        [self.lastArr addObject:cook];
    }
    
    
    self.menuList_SecView.titleLabel.text = self.title;
    self.img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , 200)];
    [self.img sd_setImageWithURL:[NSURL URLWithString:self.pic]];
    [self.menuList_SecView.backgroundView addSubview:self.img];
    
    [self tagBg];
    
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 30, 20);
    [leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"backk.png"] forState:UIControlStateNormal];
    UIBarButtonItem * custom = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = custom;
    
    
    // Do any additional setup after loading the view.
}




-(void)tagBg
{
    
    self.menuList_SecView.tableView.delegate = self;
    self.menuList_SecView.tableView.dataSource = self;
    
    
    
    self.tagBgLabel = [[UILabel alloc]init];
    self.tagBgLabel.font = [UIFont systemFontOfSize:16];
    self.tagBgLabel.numberOfLines = 0;
    
    self.tagBgLabel.text = self.tag;
    
    
    
    //    自适应高度
    self.height = [HeightWithString heightForTextLabel:self.tag width:SCREEN_WIDTH - 40 fontSize:16];
    
    self.tagBgLabel.frame = CGRectMake(20, 210 + 80, SCREEN_WIDTH - 40, self.height);
    
    
    [self.menuList_SecView.backgroundView addSubview:self.tagBgLabel];
    
    
    
    
    
    self.materials = [[UILabel alloc]initWithFrame:CGRectMake(20, self.height + 210 + 90, 200, 30)];
    self.materials.text = @"用料";
    self.materials.font = [UIFont systemFontOfSize:18];
    [self.menuList_SecView.backgroundView addSubview:self.materials];
    self.materials.textColor = [UIColor colorWithRed:192./255. green:130./255. blue:80./255. alpha:1.];
    
    
    
    self.mat_main = [[UILabel alloc]initWithFrame:CGRectMake(40, self.height + 210 + 90 + 30, 200, 30)];
    self.mat_main.text = @"主料";
    self.mat_main.textColor = [UIColor lightGrayColor];
    self.mat_main.font = [UIFont systemFontOfSize:16];
    [self.menuList_SecView.backgroundView addSubview:self.mat_main];
    
    
    
    
    
    self.mat_main_Label = [[UILabel alloc]init];
    self.mat_main_Label.text = self.ing;
    self.mat_main_Label.font = [UIFont systemFontOfSize:16];
    self.mat_main_Label.numberOfLines = 0;
    [self.menuList_SecView.backgroundView addSubview:self.mat_main_Label];
    
    
    //    自适应高度
    self.mat_height = [HeightWithString heightForTextLabel:self.ing width: SCREEN_WIDTH - 40 fontSize:16];
    self.mat_main_Label.frame = CGRectMake(40, self.height + 360, 300, self.mat_height);
    
    
    
    self.mat_other = [[UILabel alloc]initWithFrame:CGRectMake(40, self.height + 210 + 90 + 30 + 30 + self.mat_height, 200, 30)];
    self.mat_other.text = @"配料";
    self.mat_other.textColor = [UIColor lightGrayColor];
    self.mat_other.font = [UIFont systemFontOfSize:16];
    [self.menuList_SecView.backgroundView addSubview:self.mat_other];
    
    
    
    
    
    self.mat_other_Label = [[UILabel alloc]init];
    self.mat_other_Label.text = self.bur;
    self.mat_other_Label.font = [UIFont systemFontOfSize:16];
    self.mat_other_Label.numberOfLines = 0;
    [self.menuList_SecView.backgroundView addSubview:self.mat_other_Label];
    
    
    //    自适应高度
    self.bur_height = [HeightWithString heightForTextLabel:self.bur width: SCREEN_WIDTH - 40 fontSize:16];
    self.mat_other_Label.frame = CGRectMake(40, self.height + 210 + 90 + 90 + self.mat_height,SCREEN_WIDTH - 60, self.bur_height);
    
    
    
    
    
    self.stepLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, self.height + self.mat_height + self.bur_height + 400, 200, 30)];
    self.stepLabel.text = @"做法";
    self.stepLabel.textColor = [UIColor colorWithRed:192./255. green:130./255. blue:80./255. alpha:1.];
    self.stepLabel.font = [UIFont systemFontOfSize:18];
    [self.menuList_SecView.backgroundView addSubview:self.stepLabel];
    
    
    
    
    self.menuList_SecView.backgroundView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.height + 410 + self.mat_height + self.bur_height);
    self.menuList_SecView.tableView.tableHeaderView = self.menuList_SecView.backgroundView;
    
    
    
    
    
}



#pragma mark- UItableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.lastArr.count;
    //    return 10;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CookModel * mo = [self.lastArr objectAtIndex:indexPath.row];
    return 240 + mo.height;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"cell";
    MenuList_SecTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == NO) {
        
        cell = [[MenuList_SecTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    
    
    
    CookModel *model = [self.lastArr objectAtIndex:indexPath.row];
    [cell get:model];
    
    
    
    return cell;
}



-(void)leftClick
{
    [self.navigationController popViewControllerAnimated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
